yjx.controller('bannerIntroController',['$rootScope','$scope','$fetch','$stateParams','modalService','$timeout','$state','wxShareService',function($rootScope,$scope,$fetch,$stateParams,modalService,$timeout,$state,wxShareService) {
    var id = $stateParams.id,
    pendingEventId = $stateParams.pendingEventId;
    $scope.forwardId = $stateParams.forwardId;
    //$scope.name = "jjjj"
    //$scope.bannerDetail = null;

    /*转发成功后的回调*/
    $rootScope.wxShareSuc = function () {
        /*完成待办事项*/
        //alert($rootScope.identity )
        if ($rootScope.identity == 1 && pendingEventId) {
            //alert(pendingEventId)
            $fetch.fetch(
                '/share/recordRelay/content/times',
                {
                    params: {
                        userId: $rootScope.userId,
                        contentId: id,
                        pendingEventId: pendingEventId,
                        type: 3
                    },
                    cache: false,
                    //type:'POST'
                }
            ).then(function (data) {
                }).catch(function (e) {
                    modalService.mainMsgError(e.msg)
                })
        }
    }

    /*下单链接*/
    $scope.order = function (isPay) {
        //if(isPay){
        //    /*拉取客户列表*/
        //    $state.go('order', {id: id})
        //}else {
        if ($rootScope.identity == 1) {
            if ($scope.orderTag) {
                /*弹出转发框 提示转发给客户*/
                modalService.mainMsgInfo("点击右上角将下单链接转发给客户")
            } else {
                $scope.orderTag = true;
            }
        } else {
            if ($scope.forward) {
                $state.go('order', {
                    id: id,
                    forwardId: $scope.forward.userId,
                    forwardName: $scope.forward.nickname,
                    pendingEventId: pendingEventId,
                    type:2
                })
            } else {
                $state.go('order', {id: id,type:2})
            }
        }
        //}
    }
    $scope.orderTag = false;

    function getDetail() {
        $fetch.fetch(
            '/activity/getBanners',
            {
                params:{
                    id:id
                },
            }
        ).then(function(data){
                $timeout( function() {
                    if(data && data.banners && data.banners.length > 0) {
                        $scope.data = data.banners[0];
                        $rootScope.wxDesc = $scope.data.name;
                        //$rootScope.wxImg = $scope.data.bannerUrl;
                        /*转发链接签名*/
                        /*android分享链接添加#时自带参数会被微信自动添加的form等参数截掉  原因未知*/
                        if ($rootScope.isAndroid) {
                            var linkhead = "http://www.genetuan.com/"
                        } else {
                            var linkhead = "http://www.genetuan.com/#/"
                        }
                        if ($rootScope.identity == 1) {
                            if ($rootScope.isAndroid) {
                                $rootScope.link = linkhead + "?url=bannerDetail&id=" + id + "&forwardId=" + $rootScope.userId + "&pendingEventId=" + pendingEventId;
                                wxShareService.getConfig("", ['onMenuShareAppMessage', 'onMenuShareTimeline']);
                            } else {
                                $rootScope.link = linkhead + "bannerDetail?id=" + id + "&forwardId=" + $rootScope.userId + "&pendingEventId=" + pendingEventId;
                                wxShareService.getConfig("", ['onMenuShareAppMessage', 'onMenuShareTimeline']);
                            }
                            //$location.search({'id':id,'forwardId':$rootScope.userId,'pendingEventId':pendingEventId});/*将url改变成为要转发出去的url */
                        } else {
                            if ($rootScope.isAndroid) {
                                $rootScope.link = linkhead + "?url=bannerDetail&id=" + id;
                                wxShareService.getConfig("", ['onMenuShareAppMessage', 'onMenuShareTimeline']);
                            } else {
                                $rootScope.link = linkhead + "bannerDetail?id=" + id;
                                wxShareService.getConfig("", ['onMenuShareAppMessage', 'onMenuShareTimeline']);
                            }
                        }

                    }else{
                        modalService.mainMsgError("数据库中不存在该活动介绍");
                    }
                })
            }
        ).catch(function(e){
                    modalService.mainMsgError(e.msg);
            })
    }

    if(id){
        getDetail();
    }

    /*获取转发人信息*/
    if ($scope.forwardId) {
        $fetch.fetch(
            '/user/getBusinessCard',
            {
                params: {
                    id: $scope.forwardId
                }
            }
        ).then(function (data) {
                $timeout(function () {
                    if (data && data.businessCard) {
                        $scope.forward = data.businessCard;
                        //console.log($scope.forward);
                    }
                })
            }).catch(function (e) {
            })
    }
}])